<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
?><script language="javascript">

function delete_extra_options (selobj, size)
{
	while (selobj . options . length > size)
		selobj . options [selobj . options . length - 1] = null;
}

function update_module_list ()
{
	var copy_selobj = document . f . copyServerID;
	var mod_selobj = document . f . copyModuleID;
	var choice = copy_selobj . options [copy_selobj . selectedIndex] . value;

	<?
	
	$aServerModules = $BigDaddyData->GetServerModulesByServerID($_REQUEST["serverID"]);

	if (is_array($aServerModules))
	{
		foreach ($aServerModules as $nIndex => $row)
		{
			$modStr.=$row["moduleID"].",";
		}

		$modStr=substr($modStr, 0, (strlen($modStr)-1));
	}
	else
	{
		$modStr=0;
	}
	
	$aResult = $BigDaddyData->GetServerModules();

	if (is_array($aResult))
	{
		$currentServerID=0;
		foreach ($aResult as $nIndex => $row)
		{
			$sParam = str_replace("[hostname]", "", $row["parameters"]);
			$sParam = trim ($sParam);
			if ($sParam != "")
			{
				$sParam = " ($sParam)";
			}
			
			if ($currentServerID==0)
			{
				$count=0;
			?>
				if (choice == <?=$row["serverID"];?>)
				{
			<?
				$currentServerID=$row["serverID"];
			}
			else if ($row["serverID"]!=$currentServerID)
			{

		?>
				delete_extra_options (mod_selobj, <?=$count;?>);
				}
				if (choice == <?=$row["serverID"];?>)
				{

			<?
				$currentServerID=$row["serverID"];
				$count=0;
			}
			?>
			mod_selobj.options[<?=$count;?>] = new Option ("<?=addslashes($row["name"].$sParam);?>");
			mod_selobj.options[<?=$count;?>].value = <?=$row["serverModuleID"];?>;

		<?
			$count++;
		}
	?>
		delete_extra_options (mod_selobj, <?=($count);?>);
	}
	<?
	}
?>
}


</script>

<form name="f" method="post" action="/server/query_servermod.php" name="serverform" id="serverform">
<table border="0" cellpadding="5" cellspacing="1" width="500" class="formtable">
<tr valign="top">
	<td class="formfielddesc">Select Server To Copy From:<br /></td>
	<td class="formfield">
		<select name="copyServerID" size="1" class="selectfield" onChange="update_module_list();">
			<option value=""></option>
			<?
			$aCriteria = array(
				"active" => -1
			);
			$aServers = $BigDaddyData->GetServers($aCriteria);
			
			foreach ($aServers["aResults"] as $nIndex => $row)
			{
				if ($row["serverID"] != $_REQUEST["serverID"])
				{
			?>
				<option value="<?=$row["serverID"];?>"><?=$row["hostname"];?></option>
			<?
				}
			}

			?>
		</select>
	</td>
</tr>
<tr valign="top">
	<td class="formfielddesc">Select Module To Copy:<br /></td>
	<td class="formfield">
		<select name="copyModuleID" size="1" class="selectfield">
				<option>----</option>
		</select>
	</td>
</tr>
<tr valign="top">
	<td class="formfielddesc" colspan="2">
	<div align="center">
		<input type="hidden" name="action" value="copymod" />
		<input type="hidden" name="serverID" value="<?=$_REQUEST["serverID"];?>" />
	</div>

	</td>
</tr>

</table>

</form>
